angular.module('app',['routing_basics','orgSlideData'])

.controller('initialize', function($scope) {
	
	$scope.appName = "이상형 월드컵";

	
})

.controller('slideCtrl', function($scope,orgSlideData) {
	console.log('org : ' + orgSlideData.list);
	var isAddedLastItem = true;
	var slideDataListArray = [];
	var leftSlideData;
	var rightSlideData;


	$scope.initSlide = function () {
		
		slideDataListArray = [];
		
		for (var i in orgSlideData.list) {
			slideDataListArray.push(orgSlideData.list[i]); 
		}
		
		console.log('slideDataListArray : ' + slideDataListArray);
		
		//slideDataListArray = orgSlideData.list;
		
		/* suffle slideData
		var m = slideDataListArray.length, t, i;

		while (m) {
		  i = Math.floor(Math.random() * m--);
		  t = slideDataListArray[m];
		  slideDataListArray[m] = slideDataListArray[i];
		  slideDataListArray[i] = t;
		}
		*/
		
		leftSlideData = slideDataListArray[0];
		rightSlideData = slideDataListArray[1];

		slideDataListArray.splice(0,1); //call twice
		slideDataListArray.splice(0,1); //call twice

		$scope.slideDataList = slideDataListArray;
		$scope.leftSlide = leftSlideData;
		$scope.rightSlide = rightSlideData;
		
		isAddedLastItem = true;
		console.log('init Done');
	}

	$scope.initSlide();
	
	$scope.slideNextEvtTrigger = function () {
		if (!$scope.slideDataList[0]) {		
			return;
		}
		$scope.leftSlide = $scope.slideDataList.pop();
		$scope.addLastItem();
	};
	$scope.slidePrevEvtTrigger = function () {
		if (!$scope.slideDataList[0]) {		
			return;
		}
		$scope.rightSlide = $scope.slideDataList.pop();
		$scope.addLastItem();
	};
	
	
	$scope.addLastItem = function () {
		if (isAddedLastItem) {
			if ($scope.slideDataList.length == 0) {
				$scope.slideDataList.push({
					idx:'9999'
						, title:''
						, imgUrl:'http://peaktkd.net/wp-content/uploads/2014/04/winner.jpg'
						, content:''
						, bs : 'cover'
						, bp : '50% 0%'
						, isEnd : true
				});
				isAddedLastItem = false;
			}
		}
	}
	
	
})

;